<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Matrix207&#39;s Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Matrix207's Blog">
<meta property="og:url" content="http://yoursite.com/page/6/index.html">
<meta property="og:site_name" content="Matrix207's Blog">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Matrix207's Blog">
  
    <link rel="alternate" href="/atom.xml" title="Matrix207&#39;s Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Matrix207&#39;s Blog</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="Flux RSS"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Rechercher"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-lio" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/11/26/lio/" class="article-date">
  <time datetime="2014-11-25T16:00:00.000Z" itemprop="datePublished">2014-11-26</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/storage/">storage</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/11/26/lio/">LIO</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h4 id="历史"><a href="#历史" class="headerlink" title="历史"></a>历史</h4><ul>
<li>Linux 2.6.38 为分界线，此前的标准是 Linux SCSI Target , STGT 之后迄今为止的<br>标准是 Linux-IO Target , LIO 确切的说 Linus Torvalds 在 2011年1月15日将<br>LIO SCSI Target engine merge 到 Linux 2.6.38 中</li>
<li>暂时使用LIO作为IET替代，因为IET当前已不更新，最新版2010年。而LIO已进入内核，<br>怎么说这几年应该都会持续发展,属于主流应用。</li>
</ul>
<h4 id="LIO代码量"><a href="#LIO代码量" class="headerlink" title="LIO代码量"></a>LIO代码量</h4><ul>
<li><code>/home/dennis/work/kernel/linux-3.2.63/drivers/target</code></li>
<li><code>[dennis@localhost target]$ find ./* -name &quot;*.*&quot; |xargs wc -l |awk &#39;END{print $1}&#39;</code><br>52187  </li>
<li><code>[dennis@localhost target]$ find iscsi/ -name &quot;*.*&quot; |xargs wc -l |awk &#39;END{print $1}&#39;</code><br>21801  </li>
</ul>
<h4 id="开源iSCSI-Target调研"><a href="#开源iSCSI-Target调研" class="headerlink" title="开源iSCSI Target调研"></a>开源iSCSI Target调研</h4><ul>
<li>SCST与LIO  <ul>
<li>SCST是一个相对较早且比较成熟的SCSI Target开源实现。  </li>
<li>LIO相比SCST是一个更晚的SCSI Target开源实现，但在与SCST竞争进入Linux内核中，<br>却以LIO胜出告终。关于二者之间进入Linux内核时的争论，LWN上一篇很 有趣的文章，<br>A tale of two SCSI Targets，中文翻译为“SCSI Target之 双城记”。  </li>
<li>虽然LIO因为进入Linux内核而有了更好的发展前景，但SCST也不差，Fusion-io 公司<br>刚刚收购了SCST的商业支持公司ID7。</li>
</ul>
</li>
<li>Tgt  <ul>
<li>Tgt也是一个通用的SCST Target开源实现，与前两者不同的是，在支持iSCSI协 议上，<br>Tgt的所有代码是完全工作在用户态的。  </li>
<li>Tgt将LU视为backstore，支持backstore可以模块化，也就是说，你可以写一个模块来<br>支持你自己定义的LU。Tgt提供了多线程api接口，使得编写backstore时 ，可以使用多<br>个线程同时处理SCSI请求。  </li>
<li>Tgt的主线程使用epoll LT模型，监听并接收Initiator发来<br>的读写请求与命令 ，而调用对应的backstore处理模块。</li>
</ul>
</li>
<li>iSCSI Target支持LU是分布式文件系统时的优化  <ul>
<li>iSCSI Target与LU之间支持多连接并发读写请求，对于不要求排序的SCSI命令与数据，可以并发发给LU  </li>
<li>iSCSI Target对SCSI命令与数据进行合并，然后发给LU。  </li>
</ul>
</li>
<li>比较  <ul>
<li>无论是SCST还是LIO，我都不认为它们是支持分布式文件系统的最佳选择。<br>首先，它们都是工作在内核态的，一旦出问题，会导致系统挂掉，直接影响跑在系统上的其他线上服务。<br>其次，SCSI与LIO作为通用的SCSI Target实现，在处理完iSCSI协议后，会把SCSI的<br>处理交给内核SCSI Driver去处理，这对支持分布式文件做二次开发来说，相对更加困难。</li>
<li>LIO对于一个LU，分配一个recv线程与一个send线程，recv线程接收Initiator发来的<br>iSCSI PDU，解析成SCSI请求后交给send线程，send线程将请求发给LU，并将LU返回<br>的结果返回给Initiator。对于LU是分布式文件系统时，一个send线程的框架让支持<br>iSCSI Target与LU之间多连接并发读写相对比较困难。而且LIO对iSCSI协议的支持，<br>很难针对LU是分布式文件系统做优化。LIO的send线程 与recv线程使用一个队列进行<br>通信，该队列中的SCSI请求，有些不关心顺序，有些却关心，这些都是在send线程遍<br>历队列时才进行处理的。如果要支持LU的多连接并发读写，需要额外的队列来维护SCSI<br>请求，这个队列对SCSI请求到达LU的顺序没有要求。当然，也要额外支持多线程等处理。</li>
<li>Tgt由于工作在用户态，没有缺点1，而且Tgt的backstore可以模块化，开发起来非常方便，<br>同时backstore支持多线程处理，而且Tgt交给backstore的多线程处理的 list已经对顺序不作要求了。</li>
<li>从以上分析来看，使用Tgt让分布式文件系统支持iSCSI更加有优势，而且更加方便。<br>目前，开源分布式存储项目sheepdog与hlfs都是基于Tgt开发模块来支持 iSCSI协议的。</li>
</ul>
</li>
<li>Tgt的缺点与改进<ul>
<li>Tgt的backstore在使用多线程时，多个线程竞争一个list，开销较大。可以让 每个线程维护<br>一个list，主线程通过CAS无锁队列的方式，将SCSI请求根据rr算 法加入到每个线程的list中。</li>
<li>Tgt的backstore与LU之间连接数与线程数，是1：1关系，且线程数为4，写死了的。<br>可以修改代码，将连接数改为可配置的。</li>
<li>Tgt使用一个主线程通过epoll接受所有Initiator的读写请求，当登陆的Initiator较多时，<br>这里可能成为瓶颈。通常来说，这不是问题，因为会iSCSI Target会部署多个的。</li>
</ul>
</li>
</ul>
<h3 id="targetcli"><a href="#targetcli" class="headerlink" title="targetcli"></a>targetcli</h3><ul>
<li>root权限运行targetcli</li>
<li>浏览存储对象, ls查看目录树信息，cd到执行目录</li>
<li>创建文件存储对象<ul>
<li>cd /backstores/fileio</li>
<li>create disk0 /tmp/disk0.img 10MB</li>
<li>cd /backstores/ramdisk</li>
<li>create rd0 10MB</li>
</ul>
</li>
<li>创建iSCSI目标<ul>
<li>cd /iscsi </li>
<li>create [这里可以加入自定义的WWN:WorldWide Name]</li>
<li>cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e/tpg1/</li>
<li>luns/ create /backstores/fileio/disk0</li>
<li>luns/ create /backstores/ramdisk/rd0</li>
<li>portals/ create 0.0.0.0 </li>
<li>set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1</li>
<li>cd /</li>
<li>ls</li>
<li>saveconfig</li>
</ul>
</li>
<li>当使用targetcli操作完毕后，记得使用saveconfig来保存配置，要不然重启target服务后，<br>刚才的配置将丢失.  <code>targetcli saveconfig</code><br>Last 10 configs saved in /etc/target/backup.<br>Configuration saved to /etc/target/saveconfig.json</li>
<li>启动iscsi target服务<ul>
<li>[root@localhost ~]# service target start </li>
<li>[root@localhost ~]# service target status</li>
</ul>
</li>
<li>装载iSCSI Target <ul>
<li>[root@localhost ~]# iscsiadm -m discovery -t sendtargets -p 127.0.0.1<br>127.0.0.1:3260,1 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e</li>
<li>[root@localhost ~]# iscsiadm –mode node \  <blockquote>
<p>–targetname iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e \<br>–portal 127.0.0.1 –login</p>
</blockquote>
</li>
<li>上面的命令还可以使用简写模式: iscsiadm -m node -T \<blockquote>
<p>iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e \<br>-p 127.0.0.1 -l</p>
</blockquote>
</li>
<li>[root@localhost dennis]# lsscsi<br>[2:0:0:0]    disk    ATA      ST3160815AS      A     /dev/sda<br>[6:0:0:0]    disk    LIO-ORG  disk0            4.0   /dev/sdb<br>[6:0:0:1]    disk    LIO-ORG  rd0              4.0   /dev/sdc  </li>
</ul>
</li>
<li>卸载并删除iSCSI目标<ul>
<li>iscsiadm –mode node –targetname iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e –portal 127.0.0.1 –logout</li>
<li>或简写: iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e -p 127.0.0.1 -u</li>
<li>targetcli iscsi/ delete iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e </li>
</ul>
</li>
<li>Other operation<ul>
<li>iscsiadm –mode node -U all</li>
<li>iscsiadm –mode node -o delete</li>
<li>iscsiadm –mode node</li>
</ul>
</li>
</ul>
<h3 id="测试脚本"><a href="#测试脚本" class="headerlink" title="测试脚本"></a>测试脚本</h3><pre><code>mkdir -p /lio/
targetcli /backstores/fileio create disk0 /lio/disk0.img 1024MB
targetcli /iscsi create iqn.2007-10.lio.com:lio.test
targetcli /iscsi/iqn.2007-10.lio.com:lio.test/tpg1/luns/ create /backstores/fileio/disk0
targetcli /iscsi/iqn.2007-10.lio.com:lio.test/tpg1/portals/ create 0.0.0.0 
targetcli /iscsi/iqn.2007-10.lio.com:lio.test/tpg1 set attribute authentication=1 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1
targetcli /iscsi/iqn.2007-10.lio.com:lio.test/tpg1/acls/ create iqn.2007-10.lio.com:acl01
targetcli /iscsi/iqn.2007-10.lio.com:lio.test/tpg1/acls/iqn.2007-10.lio.com:acl01/ set auth userid=dennis
targetcli /iscsi/iqn.2007-10.lio.com:lio.test/tpg1/acls/iqn.2007-10.lio.com:acl01/ set auth password=Dennis@123456
targetcli saveconfig
</code></pre><h3 id="其他操作"><a href="#其他操作" class="headerlink" title="其他操作"></a>其他操作</h3><ul>
<li><p>增加本地监听ip地址和端口</p>
<p>  /iscsi/iqn.20…/tpg1/portals&gt; create 172.16.110.11 8089<br>  Created network portal 172.16.110.11:8089.<br>  /iscsi/iqn.20…/tpg1/portals&gt; ls<br>  o- portals …………………………………………… [Portals: 2]</p>
<pre><code>o- 0.0.0.0:3260 .................................................... [OK]
o- 172.16.110.11:8089 .............................................. [OK]
</code></pre><p>  /iscsi/iqn.20…/tpg1/portals&gt; status<br>  Status for /iscsi/iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6b448471ba5e/tpg1/portals: Portals: 2</p>
</li>
<li><p>Initiator访问IP限制? 目前找不到方法！原来的IET有限制指定IP访问的功能，但是并不表示<br>该功能是iscsi协议必须实现的，所以现在的LIO没有这样的功能也是合理的。</p>
</li>
<li><p>如何设置块设备的IO模式为write-back或write-through? 目前找不到方法。对于FILEIO是可以的.</p>
<p>  [root@localhost src]# targetcli /backstores/fileio/ create fileio01.dat /tmp/fileio01.dat 10M write_back=False<br>  Created fileio fileio01.dat with size 10485760<br>  [root@localhost src]# ls /tmp/fileio01.dat -lh<br>  -rw-r–r–. 1 root root 10M Feb  3 15:01 /tmp/fileio01.dat<br>  [root@localhost src]# targetcli /backstores/fileio/ ls<br>  o- fileio ……………………………………………… [Storage Objects: 1]<br>  o- fileio01.dat ………….. [/tmp/fileio01.dat (10.0MiB) write-thru deactivated]<br>  [root@localhost src]# targetcli /backstores/fileio/ create fileio02.dat /tmp/fileio02.dat 10M write_back=True<br>  Created fileio fileio02.dat with size 10485760<br>  [root@localhost src]# targetcli /backstores/fileio/ ls<br>  o- fileio ……………………………………………… [Storage Objects: 2]<br>  o- fileio01.dat ………….. [/tmp/fileio01.dat (10.0MiB) write-thru deactivated]<br>  o- fileio02.dat ………….. [/tmp/fileio02.dat (10.0MiB) write-back deactivated]  </p>
</li>
<li><p>targetcli 设置CHAP登陆: acls中创建wwn, 设置用户名和密码</p>
<ul>
<li>/&gt; cd /iscsi/iqn.2007-10.lio.com:dg2.lv1/tpg1/</li>
<li>set attribute authentication=1</li>
<li>acls/ create iqn.1991-05.com.microsoft:ibm-t410s </li>
<li>cd acls/iqn.1991-05.com.microsoft:ibm-t410s</li>
<li>set auth userid=iqn.1991-05.com.microsoft:ibm-t410s</li>
<li>set auth password=mytargetsecret</li>
<li>saveconfig</li>
<li><p>reference <a href="http://linux-iscsi.org/wiki/ISCSI" target="_blank" rel="external">http://linux-iscsi.org/wiki/ISCSI</a></p>
<p>[root@localhost dennis]# iscsiadm -m node -p 172.16.130.200 -l<br>Logging in to [iface: default, target: iqn.2007-10.lio.com:dg2.lv1, portal: 172.16.130.200,3260] (multiple)<br>iscsiadm: Could not login to [iface: default, target: iqn.2007-10.lio.com:dg2.lv1, portal: 172.16.130.200,3260].<br>iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)<br>iscsiadm: Could not log into all portals</p>
</li>
</ul>
</li>
</ul>
<h3 id="配置检查"><a href="#配置检查" class="headerlink" title="配置检查"></a>配置检查</h3><ul>
<li><p>/sys/kernel/config/target/iscsi/ </p>
<p>  [root@localhost ~]# ls -l /sys/kernel/config/target/iscsi<br>  total 0<br>  drwxr-xr-x. 2 root root    0 Dec 15 15:59 discovery_auth<br>  drwxr-xr-x. 4 root root    0 Dec 15 15:58 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f264093a034e<br>  drwxr-xr-x. 4 root root    0 Dec 15 15:59 iqn.2014-12.org.linux-iscsi.localhost.x8664:sn.f3849a0b356e<br>  -r–r–r–. 1 root root 4096 Dec 15 16:05 lio_version</p>
</li>
<li><p>当使用targetcli操作完毕后，记得使用saveconfig来保存配置，要不然重启target服务后，<br>刚才的配置将丢失.</p>
<p>  [root@localhost ~]# targetcli saveconfig<br>  Last 10 configs saved in /etc/target/backup.<br>  Configuration saved to /etc/target/saveconfig.json</p>
</li>
<li><p>关于配置文件 /etc/target/saveconfig.json的解析</p>
<ul>
<li>JSON (JavaScript Object Notation) is a lightweight data-interchange format</li>
<li>JSON 一种轻量级的数据交换格式</li>
<li><a href="http://www.json.org/" target="_blank" rel="external">http://www.json.org/</a></li>
</ul>
</li>
</ul>
<h4 id="需要验证测试的特性"><a href="#需要验证测试的特性" class="headerlink" title="需要验证测试的特性"></a>需要验证测试的特性</h4><ul>
<li>各中类型的性能比较<ul>
<li>FILEIO 性能</li>
<li>Block 性能</li>
</ul>
</li>
<li>增加或删除不用的lun是否需要重启服务，会不会影响正常业务</li>
<li>破坏性测试<ul>
<li>块设备异常是否影响其他iscsi卷的业务</li>
</ul>
</li>
<li>相比IET，有哪些新特性</li>
<li>对比所有TARGET的开源实现，有哪些优势，有无缺点</li>
</ul>
<h4 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h4><ul>
<li><a href="https://www.ibm.com/developerworks/community/blogs/5144904d-5d75-45ed-9d2b-cf1754ee936a/entry/linux_io_target%e4%bb%8b%e7%bb%8d_%e4%b8%80?lang=en" target="_blank" rel="external">Linux-IO Target介绍(一)</a></li>
<li><a href="https://www.ibm.com/developerworks/community/blogs/5144904d-5d75-45ed-9d2b-cf1754ee936a/entry/april_11_2014_12_58_am?lang=en" target="_blank" rel="external">Linux-IO Target介绍(二)</a></li>
<li><a href="http://blog.csdn.net/load2006/article/details/18088445" target="_blank" rel="external">LIO target</a></li>
<li><a href="http://linux-iscsi.org/wiki/LIO" target="_blank" rel="external">LIO</a></li>
<li><a href="http://linux-iscsi.org/wiki/ISCSI" target="_blank" rel="external">ISCSI</a></li>
<li><a href="https://en.wikipedia.org/wiki/LIO_(SCSI_target" target="_blank" rel="external">LIO wikipedia</a>)</li>
<li><a href="http://linux-iscsi.org/wiki/Features" target="_blank" rel="external">Linux SCSI Target Features</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/11/26/lio/" data-id="ciqqpe1rs00bcnmpvpfgbw1je" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/iscsi/">iscsi</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-rapidly-method-for-clean-directory-with-rsync" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/09/15/rapidly-method-for-clean-directory-with-rsync/" class="article-date">
  <time datetime="2014-09-14T16:00:00.000Z" itemprop="datePublished">2014-09-15</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/linux/">linux</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/09/15/rapidly-method-for-clean-directory-with-rsync/">Rapidly method for clean directory with rsync</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Methods"><a href="#Methods" class="headerlink" title="Methods"></a>Methods</h3><ul>
<li>rm</li>
<li>rsync</li>
</ul>
<h3 id="Test"><a href="#Test" class="headerlink" title="Test"></a>Test</h3><pre><code>[dennis@localhost ttt]$ mkdir empty
[dennis@localhost ttt]$ mkdir tmp/; seq 1 40000 | xargs -I{} touch tmp/file_{} 
[dennis@localhost ttt]$ mkdir tmp1/; time seq 1 40000 | xargs -I{} touch tmp1/file_{} 

real    0m28.781s
user    0m0.361s
sys    0m3.091s
[dennis@localhost ttt]$ ls -ld *
drwxrwxr-x. 2 dennis dennis    4096 Sep 15 09:07 empty
drwxrwxr-x. 2 dennis dennis 1114112 Sep 15 09:11 tmp
drwxrwxr-x. 2 dennis dennis 1114112 Sep 15 09:13 tmp1
[dennis@localhost ttt]$ strace -c rsync -a --delete empty/ tmp/
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 98.91    0.001000         100        10         1 select
  1.09    0.000011           2         6         3 wait4
  0.00    0.000000           0        15           read
  0.00    0.000000           0         5           write
  0.00    0.000000           0        21         9 open
  0.00    0.000000           0        20           close
  0.00    0.000000           0         5         3 stat
  0.00    0.000000           0        12           fstat
  0.00    0.000000           0         1           lstat
  0.00    0.000000           0        25           mmap
  0.00    0.000000           0        12           mprotect
  0.00    0.000000           0         6           munmap
  0.00    0.000000           0         6           brk
  0.00    0.000000           0        10           rt_sigaction
  0.00    0.000000           0         1           rt_sigprocmask
  0.00    0.000000           0         1         1 rt_sigreturn
  0.00    0.000000           0         1         1 access
  0.00    0.000000           0         4           socket
  0.00    0.000000           0         4         4 connect
  0.00    0.000000           0         2           socketpair
  0.00    0.000000           0         1           clone
  0.00    0.000000           0         1           execve
  0.00    0.000000           0        11           fcntl
  0.00    0.000000           0         4           getdents
  0.00    0.000000           0         1           getcwd
  0.00    0.000000           0         1           chdir
  0.00    0.000000           0         2           umask
  0.00    0.000000           0         1           geteuid
  0.00    0.000000           0         1           getegid
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         2           openat
------ ----------- ----------- --------- --------- ----------------
100.00    0.001011                   193        22 total
[dennis@localhost ttt]$ strace -c rm -rf tmp1/
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 79.25    0.035329           1     40001           unlinkat
 17.50    0.007800         186        42           getdents
  3.07    0.001369           7       196           brk
  0.18    0.000082          21         4           munmap
  0.00    0.000000           0         2           read
  0.00    0.000000           0         8         4 open
  0.00    0.000000           0        10           close
  0.00    0.000000           0         4         3 stat
  0.00    0.000000           0         6           fstat
  0.00    0.000000           0         1           lstat
  0.00    0.000000           0         1         1 lseek
  0.00    0.000000           0        11           mmap
  0.00    0.000000           0         4           mprotect
  0.00    0.000000           0         1           ioctl
  0.00    0.000000           0         1         1 access
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         9           fcntl
  0.00    0.000000           0         1           fstatfs
  0.00    0.000000           0         1           arch_prctl
  0.00    0.000000           0         2           openat
  0.00    0.000000           0         1           newfstatat
------ ----------- ----------- --------- --------- ----------------
100.00    0.044580                 40307         9 total
</code></pre><h3 id="Analyze-system-call"><a href="#Analyze-system-call" class="headerlink" title="Analyze system call"></a>Analyze system call</h3><ul>
<li><p>rm<br>Do so many system calls, special of unlinkat, it take of 79.25% of time,   </p>
</li>
<li><p>rsync  </p>
</li>
</ul>
<h3 id="Analyze-source-code"><a href="#Analyze-source-code" class="headerlink" title="Analyze source code"></a>Analyze source code</h3><ul>
<li><a href="http://rsync.samba.org/" target="_blank" rel="external">rsync</a></li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://www.quora.com/How-can-someone-rapidly-delete-400-000-files" target="_blank" rel="external">How can someone rapidly delete 400,000 files?</a></li>
<li><a href="http://blog.chinaunix.net/uid-10705106-id-3879288.html" target="_blank" rel="external">为什么rsync能够快速删除400000文件</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/09/15/rapidly-method-for-clean-directory-with-rsync/" data-id="ciqqpe1rl00b9nmpvomiriqup" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-linux-performace-tools" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/09/08/linux-performace-tools/" class="article-date">
  <time datetime="2014-09-07T16:00:00.000Z" itemprop="datePublished">2014-09-08</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/tools/">tools</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/09/08/linux-performace-tools/">linux performace tools</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>###</p>
<p><img src="/assets/image/posts/perf/linux_benchmarking_tools.png" alt="linux benchmarking tools"></p>
<p><img src="/assets/image/posts/perf/linux_observability_sar.png" alt="linux observability sar"></p>
<p><img src="/assets/image/posts/perf/linux_tuning_tools.png" alt="linux tuning tools"></p>
<h3 id="Tools-Basic"><a href="#Tools-Basic" class="headerlink" title="Tools: Basic"></a>Tools: Basic</h3><ul>
<li>uptime</li>
<li>top or htop</li>
<li>mpstat</li>
<li>iostat</li>
<li>vmstat</li>
<li>free </li>
<li>ping</li>
<li>nicstat</li>
<li>dstat</li>
</ul>
<h3 id="Tools-Intermediate"><a href="#Tools-Intermediate" class="headerlink" title="Tools: Intermediate"></a>Tools: Intermediate</h3><ul>
<li>sar</li>
<li>netstat</li>
<li>pidstat</li>
<li>strace</li>
<li>tcpdump</li>
<li>blktrace</li>
<li>iotop</li>
<li>slabtop</li>
<li>sysctl</li>
<li>/proc</li>
</ul>
<h3 id="Tools-Advanced"><a href="#Tools-Advanced" class="headerlink" title="Tools: Advanced"></a>Tools: Advanced</h3><ul>
<li>perf<ul>
<li><code>perf record program [program_option]</code></li>
<li><code>perf report</code></li>
</ul>
</li>
<li>DTrace</li>
<li>SystemTap</li>
<li>and more…<ul>
<li>ps</li>
<li>pmap</li>
<li>traceroute</li>
<li>ntop</li>
<li>ss</li>
<li>lsof</li>
<li>oprofile</li>
<li>gprof</li>
<li>kcachegrind</li>
<li>valgrind</li>
<li>google profiler</li>
<li>nfsiostat</li>
<li>cifsiostat</li>
<li>latencytop</li>
<li>powertop</li>
<li>LLTng</li>
<li>ktap</li>
</ul>
</li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://www.brendangregg.com/linuxperf.html" target="_blank" rel="external">Linux Performance</a></li>
<li><a href="http://www.slideshare.net/brendangregg/linux-performance-analysis-and-tools" target="_blank" rel="external">Linux performance analysis and tools</a></li>
<li><a href="http://www.vpsee.com/tag/performance/" target="_blank" rel="external">Tag: performance</a></li>
<li><a href="https://perf.wiki.kernel.org/index.php/Tutorial" target="_blank" rel="external">perf wiki</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/09/08/linux-performace-tools/" data-id="ciqqpe1rg00b6nmpvhnpwzthc" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/performance/">performance</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-sync" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/09/07/sync/" class="article-date">
  <time datetime="2014-09-06T16:00:00.000Z" itemprop="datePublished">2014-09-07</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/tools/">tools</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/09/07/sync/">sync</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Introduce"><a href="#Introduce" class="headerlink" title="Introduce"></a>Introduce</h3><p>sync, linux command, using to write any data buffer in memory out to disk.</p>
<p>It do nothing, but exercise the ‘sync’ system call</p>
<p>So, if we want to study what the ‘sync’ really do, go in the kernel.</p>
<h3 id="sync-command"><a href="#sync-command" class="headerlink" title="sync command"></a>sync command</h3><p>File: coreutils-8.9/src/sync.c</p>
<pre><code>int
main (int argc, char **argv)
{
  initialize_main (&amp;argc, &amp;argv);
  set_program_name (argv[0]);
  setlocale (LC_ALL, &quot;&quot;);
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  atexit (close_stdout);

  parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version,
                      usage, AUTHORS, (char const *) NULL);
  if (getopt_long (argc, argv, &quot;&quot;, NULL, NULL) != -1)
    usage (EXIT_FAILURE);

  if (optind &lt; argc)
    error (0, 0, _(&quot;ignoring all arguments&quot;));

  sync ();
  exit (EXIT_SUCCESS);
}
</code></pre><p>Do nothing, but do system call <code>sync()</code></p>
<h3 id="sync-architecture-in-kernel"><a href="#sync-architecture-in-kernel" class="headerlink" title="sync architecture in kernel"></a>sync architecture in kernel</h3><p>system call <code>sync()</code> is defined in fs/sync.c</p>
<pre><code>/*
 * sync everything.  Start out by waking pdflush, because that writes back
 * all queues in parallel.
 */
SYSCALL_DEFINE0(sync)
{
    wakeup_flusher_threads(0);
    sync_filesystems(0);
    sync_filesystems(1);
    if (unlikely(laptop_mode))
        laptop_sync_completion();
    return 0;
}
</code></pre><p><code>sync</code> call <code>sync_filesystems</code>  </p>
<pre><code>static void sync_filesystems(int wait)
{
    struct super_block *sb;
    static DEFINE_MUTEX(mutex);

    mutex_lock(&amp;mutex);        /* Could be down_interruptible */
    spin_lock(&amp;sb_lock);
    list_for_each_entry(sb, &amp;super_blocks, s_list)
        sb-&gt;s_need_sync = 1;

restart:
    list_for_each_entry(sb, &amp;super_blocks, s_list) {
        if (!sb-&gt;s_need_sync)
            continue;
        sb-&gt;s_need_sync = 0;
        sb-&gt;s_count++;
        spin_unlock(&amp;sb_lock);

        down_read(&amp;sb-&gt;s_umount);
        if (!(sb-&gt;s_flags &amp; MS_RDONLY) &amp;&amp; sb-&gt;s_root &amp;&amp; sb-&gt;s_bdi)
            __sync_filesystem(sb, wait);
        up_read(&amp;sb-&gt;s_umount);

        /* restart only when sb is no longer on the list */
        spin_lock(&amp;sb_lock);
        if (__put_super_and_need_restart(sb))
            goto restart;
    }
    spin_unlock(&amp;sb_lock);
    mutex_unlock(&amp;mutex);
}
</code></pre><p><code>sync_filesystems</code> call <code>__sync_filesystem</code> </p>
<pre><code>static int __sync_filesystem(struct super_block *sb, int wait)
{
    /*
     * This should be safe, as we require bdi backing to actually
     * write out data in the first place
     */
    if (!sb-&gt;s_bdi)
        return 0;

    /* Avoid doing twice syncing and cache pruning for quota sync */
    if (!wait) {
        writeout_quota_sb(sb, -1);
        writeback_inodes_sb(sb);
    } else {
        sync_quota_sb(sb, -1);
        sync_inodes_sb(sb);
    }
    if (sb-&gt;s_op-&gt;sync_fs)
        sb-&gt;s_op-&gt;sync_fs(sb, wait);
    return __sync_blockdev(sb-&gt;s_bdev, wait);
}
</code></pre><p><code>__sync_filesystem</code> call <code>sb-&gt;s_op-&gt;sync_fs(sb, wait)</code>, each filesystem should<br>implement the sync_fs()</p>
<h3 id="when-to-use"><a href="#when-to-use" class="headerlink" title="when to use"></a>when to use</h3><ol>
<li>before shutdown computer, using <code>sync</code> more than twice</li>
<li>after write big file to disk, such as using command <code>cp</code></li>
<li>to be continue</li>
</ol>
<h3 id="sync-fsync-fdatasync"><a href="#sync-fsync-fdatasync" class="headerlink" title="sync,fsync,fdatasync"></a>sync,fsync,fdatasync</h3><ul>
<li>sync, add the modified buffer to write_queue, then return immediately, not wait<br>for the reality disk writed.</li>
<li>fsync, used for single file with specify file description,and wait the disk write finish.</li>
<li>fdatasync, similar to fsync, but just do effect to the data part. fsync make<br>effect to data and file property.</li>
</ul>
<h3 id="special-application"><a href="#special-application" class="headerlink" title="special application"></a>special application</h3><ol>
<li>How if I want to sync from serval Virtual Disks, and ignore serval VDs</li>
<li>To be continue</li>
</ol>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li>man sync</li>
<li>info coreutils ‘sync invocation’ </li>
<li>kernel code</li>
<li><a href="ftp://ftp.gnu.org/gnu/coreutils/coreutils-8.9.tar.xz" target="_blank" rel="external">coreutils-8.9</a></li>
<li><a href="http://jesserei.blog.163.com/blog/static/121411689201032015129673/" target="_blank" rel="external">sync、fsync和fdatasync函数</a></li>
<li><a href="http://www.2cto.com/os/201204/126687.html" target="_blank" rel="external">缓存同步操作–sys_sync系统调用</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/09/07/sync/" data-id="ciqqpe1re00b3nmpvh2e9g0e4" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/sync/">sync</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-bash-trap" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/09/06/bash-trap/" class="article-date">
  <time datetime="2014-09-05T16:00:00.000Z" itemprop="datePublished">2014-09-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/language/">language</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/09/06/bash-trap/">bash trap</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>From <a href="http://blog.charlee.li/bash-pitfalls/" target="_blank" rel="external">http://blog.charlee.li/bash-pitfalls/</a></p>
<p>感谢fcicq，他的new 30 days系列为我们带来了不少好文章。</p>
<p>今天想分析的是这篇Bash Pitfalls, 介绍了一些bash编程中的经典错误。fcicq说可能不适<br>合初学者，而我认为， 正是bash编程的初学者才应该好好阅读一下这篇文章。</p>
<p>下面就逐个分析一下这篇文章中提到的错误。不是完全的翻译，有些没用的话就略过了，<br>有些地方则加了些注释。</p>
<ul>
<li>1.for i in `ls *.mp3`</li>
</ul>
<p>常见的错误写法：</p>
<pre><code>for i in `ls *.mp3`; do     # Wrong!
</code></pre><p>为什么错误呢？因为for…in语句是按照空白来分词的，包含空格的文件名会被拆成多个词。<br>如遇到 01 - Don’t Eat the Yellow Snow.mp3 时，i的值会依次取 01，-，Don’t，等等。</p>
<p>用双引号也不行，它会将ls *.mp3的全部结果当成一个词来处理。</p>
<pre><code>for i in &quot;`ls *.mp3`&quot;; do   # Wrong!
</code></pre><p>正确的写法是</p>
<pre><code>for i in *.mp3; do
</code></pre><ul>
<li>2.<code>cp $file $target</code></li>
</ul>
<p>这句话基本上正确，但同样有空格分词的问题。所以应当用双引号：</p>
<pre><code>cp &quot;$file&quot; &quot;$target&quot;
</code></pre><p>但是如果凑巧文件名以 - 开头，这个文件名会被 cp 当作命令行选项来处理，依旧很头疼。<br>可以试试下面这个。</p>
<pre><code>cp -- &quot;$file&quot; &quot;$target&quot;
</code></pre><p>运气差点的再碰上一个不支持 – 选项的系统，那只能用下面的方法了：使每个变量都以目录开头。</p>
<pre><code>for i in ./*.mp3; do
  cp &quot;$i&quot; /target
  ...
</code></pre><ul>
<li>3.<code>[ $foo = &quot;bar&quot; ]</code></li>
</ul>
<p>当$foo为空时，上面的命令就变成了</p>
<pre><code>[ = &quot;bar&quot; ]
</code></pre><p>类似地，当$foo包含空格时：</p>
<pre><code>[ multiple words here = &quot;bar&quot; ]
</code></pre><p>两者都会出错。所以应当用双引号将变量括起来：</p>
<pre><code>[ &quot;$foo&quot; = bar ]      # 几乎完美了。
</code></pre><p>但是当$foo以 - 开头时依然会有问题。 在较新的bash中你可以用下面的方法来代替，<br>[[ 关键字能正确处理空白、空格、带横线等问题。</p>
<pre><code>[[ $foo = bar ]]      # 正确
</code></pre><p>旧版本bash中可以用这个技巧（虽然不好理解）：</p>
<pre><code>[ x&quot;$foo&quot; = xbar ]    # 正确
</code></pre><p>或者干脆把变量放在右边，因为 [ 命令的等号右边即使是空白或是横线开头，依然能正常<br>工作。 （Java编程风格中也有类似的做法，虽然目的不一样。）</p>
<pre><code>[ bar = &quot;$foo&quot; ]      # 正确
</code></pre><ul>
<li>4.cd `dirname “$f”`</li>
</ul>
<p>同样也存在空格问题。那么加上引号吧。</p>
<pre><code>cd &quot;`dirname &quot;$f&quot;`&quot;
</code></pre><p>问题来了，是不是写错了？由于双引号的嵌套，你会认为<code>dirname 是第一个字符串，</code>是<br>第二个字符串。 错了，那是C语言。在bash中，命令替换（反引号``中的内容）里面的双引<br>号会被正确地匹配到一起， 不用特意去转义。</p>
<p>$()语法也相同，如下面的写法是正确的。</p>
<pre><code>cd &quot;$(dirname &quot;$f&quot;)&quot;
</code></pre><ul>
<li>5.<code>[ &quot;$foo&quot; = bar &amp;&amp; &quot;$bar&quot; = foo ]</code></li>
</ul>
<p>[ 中不能使用 &amp;&amp; 符号！因为 [ 的实质是 test 命令，&amp;&amp; 会把这一行分成两个命令的。应<br>该用以下的写法。</p>
<pre><code>[ bar = &quot;$foo&quot; -a foo = &quot;$bar&quot; ]       # Right!
[ bar = &quot;$foo&quot; ] &amp;&amp; [ foo = &quot;$bar&quot; ]   # Also right!
[[ $foo = bar &amp;&amp; $bar = foo ]]         # Also right!
</code></pre><ul>
<li>6.<code>[ $foo &gt; 7 ]</code></li>
</ul>
<p>很可惜 [[ 只适用于字符串，不能做数字比较。数字比较应当这样写：</p>
<pre><code>(( $foo &gt; 7 ))
</code></pre><p>或者用经典的写法：</p>
<pre><code>[ $foo -gt 7 ]
</code></pre><p>但上述使用 -gt 的写法有个问题，那就是当 $foo 不是数字时就会出错。你必须做好类型检验。</p>
<p>这样写也行。</p>
<pre><code>[[ $foo -gt 7 ]]
</code></pre><ul>
<li>7.<code>grep foo bar | while read line; do ((count++)); done</code></li>
</ul>
<p>这行代码数出bar文件中包含foo的行数，虽然很麻烦（等同于<code>grep -c foo bar</code>或者 <code>grep 
foo bar | wc -l</code>）。 乍一看没有问题，但执行之后count变量却没有值。因为管道中的每<br>个命令都放到一个新的子shell中执行， 所以子shell中定义的count变量无法传递出来。</p>
<ul>
<li>8.<code>if [grep foo myfile]</code></li>
</ul>
<p>初学者常犯的错误，就是将 if 语句后面的 [ 当作if语法的一部分。实际上它是一个命令<br>，相当于 test 命令， 而不是 if 语法。这一点C程序员特别应当注意。</p>
<p>if 会将 if 到 then 之间的所有命令的返回值当作判断条件。因此上面的语句应当写成</p>
<pre><code>if grep foo myfile &gt; /dev/null; then
</code></pre><ul>
<li>9.<code>if [bar=&quot;$foo&quot;]</code></li>
</ul>
<p>同样，[ 是个命令，不是 if 语句的一部分，所以要注意空格。</p>
<pre><code>if [ bar = &quot;$foo&quot; ]
</code></pre><ul>
<li>10.<code>if [ [ a = b ] &amp;&amp; [ c = d ] ]</code></li>
</ul>
<p>同样的问题，[ 不是 if 语句的一部分，当然也不是改变逻辑判断的括号。它是一个命令。<br>可能C程序员比较容易犯这个错误？</p>
<pre><code>if [ a = b ] &amp;&amp; [ c = d ]        # 正确
</code></pre><ul>
<li>11.<code>cat file | sed s/foo/bar/ &gt; file</code></li>
</ul>
<p>你不能在同一条管道操作中同时读写一个文件。根据管道的实现方式，file要么被截断成0<br>字节，要么会无限增长直到填满整个硬盘。 如果想改变原文件的内容，只能先将输出写到<br>临时文件中再用mv命令。</p>
<pre><code>sed &apos;s/foo/bar/g&apos; file &gt; tmpfile &amp;&amp; mv tmpfile file
</code></pre><ul>
<li>12.<code>echo $foo</code></li>
</ul>
<p>这句话还有什么错误码？一般来说是正确的，但下面的例子就有问题了。</p>
<pre><code>MSG=&quot;Please enter a file name of the form *.zip&quot;
echo $MSG         # 错误！
</code></pre><p>如果恰巧当前目录下有zip文件，就会显示成</p>
<pre><code>Please enter a file name of the form freenfss.zip lw35nfss.zip
</code></pre><p>所以即使是echo也别忘记给变量加引号。</p>
<ul>
<li>13.<code>$foo=bar</code></li>
</ul>
<p>变量赋值时无需加 $ 符号——这不是Perl或PHP。</p>
<ul>
<li>14.<code>foo = bar</code></li>
</ul>
<p>变量赋值时等号两侧不能加空格——这不是C语言。</p>
<ul>
<li>15.<code>echo &lt;&lt;EOF</code></li>
</ul>
<p>here document是个好东西，它可以输出成段的文字而不用加引号也不用考虑换行符的处理<br>问题。 不过here document输出时应当使用cat而不是echo。</p>
<pre><code># This is wrong:
echo &lt;&lt;EOF
Hello world
EOF


# This is right:
cat &lt;&lt;EOF
Hello world
EOF
</code></pre><ul>
<li>16.<code>su -c &#39;some command&#39;</code></li>
</ul>
<p>原文的意思是，这条基本上正确，但使用者的目的是要将 -c ‘some command’ 传给shell。<br>而恰好 su 有个 -c 参数，所以su 只会将 ‘some command’ 传给shell。所以应该这么写：</p>
<pre><code>su root -c &apos;some command&apos;
</code></pre><p>但是在我的平台上，man su 的结果中关于 -c 的解释为</p>
<pre><code>-c, --commmand=COMMAND
            pass a single COMMAND to the shell with -c
</code></pre><p>也就是说，-c ‘some command’ 同样会将 -c ‘some command’ 这样一个字符串传递给shell<br>， 和这条就不符合了。不管怎样，先将这一条写在这里吧。</p>
<ul>
<li>17.<code>cd /foo; bar</code></li>
</ul>
<p>cd有可能会出错，出错后 bar 命令就会在你预想不到的目录里执行了。所以一定要记得判断cd的返回值。</p>
<pre><code>cd /foo &amp;&amp; bar
</code></pre><p>如果你要根据cd的返回值执行多条命令，可以用 ||。</p>
<pre><code>cd /foo || exit 1;
bar
baz
</code></pre><p>关于目录的一点题外话，假设你要在shell程序中频繁变换工作目录，如下面的代码：</p>
<pre><code>find ... -type d | while read subdir; do
  cd &quot;$subdir&quot; &amp;&amp; whatever &amp;&amp; ... &amp;&amp; cd -
done
</code></pre><p>不如这样写：</p>
<pre><code>find ... -type d | while read subdir; do
  (cd &quot;$subdir&quot; &amp;&amp; whatever &amp;&amp; ...)
done
</code></pre><p>括号会强制启动一个子shell，这样在这个子shell中改变工作目录不会影响父shell（执行<br>这个脚本的shell）， 就可以省掉cd - 的麻烦。</p>
<p>你也可以灵活运用 pushd、popd、dirs 等命令来控制工作目录。</p>
<ul>
<li>18.<code>[ bar == &quot;$foo&quot; ]</code></li>
</ul>
<p>[ 命令中不能用 ==，应当写成</p>
<pre><code>[ bar = &quot;$foo&quot; ] &amp;&amp; echo yes
[[ bar == $foo ]] &amp;&amp; echo yes
</code></pre><ul>
<li>19.<code>for i in {1..10}; do ./something &amp;; done</code></li>
</ul>
<p>&amp; 后面不应该再放 ; ，因为 &amp; 已经起到了语句分隔符的作用，无需再用;。</p>
<pre><code>for i in {1..10}; do ./something &amp; done
</code></pre><ul>
<li>20.<code>cmd1 &amp;&amp; cmd2 || cmd3</code></li>
</ul>
<p>有人喜欢用这种格式来代替 if…then…else 结构，但其实并不完全一样。如果cmd2返回<br>一个非真值，那么cmd3则会被执行。 所以还是老老实实地用 if cmd1; then cmd2; else<br>cmd3 为好。</p>
<ul>
<li>21.UTF-8的BOM(Byte-Order Marks)问题</li>
</ul>
<p>UTF-8编码可以在文件开头用几个字节来表示编码的字节顺序，这几个字节称为BOM。但Unix<br>格式的UTF-8编码不需要BOM。 多余的BOM会影响shell解析，特别是开头的 #!/bin/sh 之类<br>的指令将会无法识别。</p>
<p>MS-DOS格式的换行符(CRLF)也存在同样的问题。如果你将shell程序保存成DOS格式，脚本就无法执行了。</p>
<pre><code>$ ./dos
-bash: ./dos: /bin/sh^M: bad interpreter: No such file or directory
</code></pre><ul>
<li>22.<code>echo &quot;Hello World!&quot;</code></li>
</ul>
<p>交互执行这条命令会产生以下的错误：</p>
<pre><code>-bash: !&quot;: event not found
</code></pre><p>因为 !” 会被当作命令行历史替换的符号来处理。不过在shell脚本中没有这样的问题。</p>
<p>不幸的是，你无法使用转义符来转义!：</p>
<pre><code>$ echo &quot;hi\!&quot;
hi\!
</code></pre><p>解决方案之一，使用单引号，即</p>
<pre><code>$ echo &apos;Hello, world!&apos;
</code></pre><p>如果你必须使用双引号，可以试试通过 set +H 来取消命令行历史替换。</p>
<pre><code>set +H
echo &quot;Hello, world!&quot;
</code></pre><ul>
<li>23.<code>for arg in $*</code></li>
</ul>
<p>$*表示所有命令行参数，所以你可能想这样写来逐个处理参数，但参数中包含空格时就会失败。如：</p>
<pre><code>#!/bin/bash
# Incorrect version
for x in $*; do
  echo &quot;parameter: &apos;$x&apos;&quot;
done


$ ./myscript &apos;arg 1&apos; arg2 arg3
parameter: &apos;arg&apos;
parameter: &apos;1&apos;
parameter: &apos;arg2&apos;
parameter: &apos;arg3&apos;
</code></pre><p>正确的方法是使用 $@。</p>
<pre><code>#!/bin/bash
# Correct version
for x in &quot;$@&quot;; do
  echo &quot;parameter: &apos;$x&apos;&quot;
done


$ ./myscript &apos;arg 1&apos; arg2 arg3
parameter: &apos;arg 1&apos;
parameter: &apos;arg2&apos;
parameter: &apos;arg3&apos;
</code></pre><p>在 bash 的手册中对 $* 和 $@ 的说明如下：</p>
<pre><code>*    Expands to the positional parameters, starting from one.  
     When the expansion occurs within double quotes, it 
     expands to a single word with the value of each parameter 
     separated by the first character of the IFS special variable.  
     That is, &quot;$*&quot; is equivalent to &quot;$1c$2c...&quot;,
@    Expands to the positional parameters, starting from one. 
     When the expansion occurs within double quotes, each 
     parameter expands to a separate word.  That  is,  &quot;$@&quot;  
     is equivalent to &quot;$1&quot; &quot;$2&quot; ...  
</code></pre><p>可见，不加引号时 $<em> 和 $@ 是相同的，但$</em> 会被扩展成一个字符串，而 $@ 会 被扩展成每一个参数。</p>
<ul>
<li>24.<code>function foo()</code></li>
</ul>
<p>在bash中没有问题，但其他shell中有可能出错。不要把 function 和括号一起使用。 最为<br>保险的做法是使用括号，即</p>
<pre><code>foo() {
  ...
}
</code></pre>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/09/06/bash-trap/" data-id="ciqqpe1rb00b0nmpvpvmz84xu" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/shell/">shell</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-mbr" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/09/02/mbr/" class="article-date">
  <time datetime="2014-09-01T16:00:00.000Z" itemprop="datePublished">2014-09-02</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/others/">others</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/09/02/mbr/">mbr</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Introduce"><a href="#Introduce" class="headerlink" title="Introduce"></a>Introduce</h3><p><strong>MBR</strong>, is abbreviate from <strong>M</strong>aster <strong>B</strong>oot <strong>R</strong>ecord.</p>
<p>MBR(512Bytes) = </p>
<p>partition entry</p>
<p> 0     1byte   partition flag<br> 1~3   3bytes  CHS address<br> 4     1bytes  File system flag<br> 5~7   3bytes  CHS address<br> 8~11  4bytes  start of sector<br>12~15  4bytes  count of sector </p>
<p>File system flag:<br>00H<br>01H  FAT12<br>04H  FAT16 small than 32MB<br>05H  Extended<br>06H  FAT16 large than 32MB<br>07H  HPES or NTFS<br>0BH  Windows95 FAT32<br>0CH  Windows95 FAT32<br>0EH  Windows95 FAT16<br>0FH  Windows95 Extended(large than 8G)<br>82H  Linux swap<br>83H  Linux<br>85H  Linux extended<br>86H  NTFS volume set<br>87H  NTFS volume set  </p>
<h3 id="A-case"><a href="#A-case" class="headerlink" title="A case"></a>A case</h3><p>The current os is CentOS 6.4 X86_64, running on /dev/sdb, which is a SSD disk.</p>
<pre><code>[root@localhost ~]# dd if=/dev/sdb of=/root/ssd.dat bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00146756 s, 349 kB/s
[root@localhost ~]# hexdump -C ssd.dat 
00000000  eb 48 90 d0 bc 00 7c fb  50 07 50 1f fc be 1b 7c  |.H....|.P.P....||
00000010  bf 1b 06 50 57 b9 e5 01  f3 a4 cb bd be 07 b1 04  |...PW...........|
00000020  38 6e 00 7c 09 75 13 83  c5 10 e2 f4 cd 18 8b f5  |8n.|.u..........|
00000030  83 c6 10 49 74 19 38 2c  74 f6 a0 b5 07 b4 03 02  |...It.8,t.......|
00000040  80 00 00 80 98 3e 04 00  00 08 fa 90 90 f6 c2 80  |.....&gt;..........|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|&lt;.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}&lt;.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&amp;B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..&lt;.u...........|
000001b0  00 00 00 00 00 00 00 00  a9 51 05 00 00 00 80 20  |.........Q..... |
000001c0  21 00 83 65 24 41 00 08  00 00 00 00 10 00 00 65  |!..e$A.........e|
000001d0  25 41 82 90 85 4b 00 08  10 00 00 00 80 00 00 90  |%A...K..........|
000001e0  86 4b 83 fe ff ff 00 08  90 00 00 20 2a 03 00 00  |.K......... *...|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
</code></pre><p>/dev/sda is a virtual disk of raid1(raid with two disks);<br>boot.disk, which is backup with <code>dd if=/dev/sda1 of=/root/backup/boot.disk</code>,<br>not had mbr info!</p>
<pre><code>[root@localhost ~]# dd if=/root/backup/boot.disk of=/root/b.dat bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.0019702 s, 260 kB/s
[root@localhost ~]# hexdump -C b.dat 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200
</code></pre><p>The new raid1 logic disk not had any mbr info, what I had done before was:<br><code>dd if=/root/backup/boot.disk of=/dev/sda1</code><br><code>dd if=/root/backup/root.disk of=/dev/sda2</code>  </p>
<pre><code>[root@localhost ~]# dd if=/dev/sda of=/root/raid1.dat bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00175408 s, 292 kB/s
[root@localhost ~]# hexdump -C raid1.dat 
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  c2 02 0b 00 00 00 80 20  |............... |
000001c0  21 00 83 9f 06 19 00 08  00 00 00 40 06 00 00 9f  |!..........@....|
000001d0  07 19 83 fe ff ff 00 48  06 00 00 00 00 01 00 fe  |.......H........|
000001e0  ff ff 82 fe ff ff 00 48  06 01 00 20 80 00 00 00  |.......H... ....|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
</code></pre><p>With such virtual disk, I can’t boot to run OS normal, it stop with an flashing<br>underline, if normal it should show a grub to boot the os.</p>
<p>So, I think, when I backup the OS, I should backup the MBR also, when restore I<br>should restore it to new disk.</p>
<p>Below, I using DVD to write the MBR to /dev/sda, then it show correct 512B info  </p>
<pre><code>[root@localhost ~]# dd if=/dev/sda of=/root/raid1-ok.dat bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000300859 s, 1.7 MB/s
[root@localhost ~]# hexdump -C raid1-ok.dat 
00000000  eb 48 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.H..............|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 03 02  |.........|...t..|
00000040  80 00 00 80 7a 61 00 00  00 08 fa 90 90 f6 c2 80  |....za..........|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|&lt;.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}&lt;.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&amp;B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..&lt;.u...........|
000001b0  00 00 00 00 00 00 00 00  c2 02 0b 00 00 00 80 20  |............... |
000001c0  21 00 83 9f 06 19 00 08  00 00 00 40 06 00 00 9f  |!..........@....|
000001d0  07 19 83 fe ff ff 00 48  06 00 00 00 00 01 00 fe  |.......H........|
000001e0  ff ff 82 fe ff ff 00 48  06 01 00 20 80 00 00 fe  |.......H... ....|
000001f0  ff ff 05 fe ff ff 00 68  86 01 00 d0 2d e7 55 aa  |.......h....-.U.|
00000200
</code></pre><h3 id="Questions"><a href="#Questions" class="headerlink" title="Questions"></a>Questions</h3><ol>
<li>Why maximum of partitions is 4 primary or 3 primary with another extended?<br>Because for MBR, there only 64 bytes for partition, and each partition used 16<br>bytes.</li>
</ol>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="https://en.wikipedia.org/wiki/Master_boot_record" target="_blank" rel="external">Master Boot Record</a></li>
<li><a href="http://www.blogfshare.com/mbr-dpt-ebr.html" target="_blank" rel="external">MBR分区结构、DPT分区表、EBR扩展引导</a></li>
<li><a href="http://dengqi.blog.51cto.com/5685776/1348951" target="_blank" rel="external">详解MBR分区结构以及GPT分区结构</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/09/02/mbr/" data-id="ciqqpe1r700axnmpvzz6cljxt" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/others/">others</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-grep" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/08/22/grep/" class="article-date">
  <time datetime="2014-08-21T16:00:00.000Z" itemprop="datePublished">2014-08-22</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/tools/">tools</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/08/22/grep/">grep</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="syntax"><a href="#syntax" class="headerlink" title="syntax"></a>syntax</h3><ul>
<li><p>grep [OPTIONS] PATTERN [FILE…]<br>grep [OPTIONS] [-e PATTERN | -f FILE] [FILE…]</p>
<ul>
<li>-A get the above line with match lines</li>
<li>-B get the below line with match lines</li>
<li>-c count the lines</li>
<li>-E regular expression</li>
<li>-i ignore case</li>
<li>–include=”*.c” only search c files</li>
<li>-l file with matches</li>
<li>-L file without matches</li>
<li>-n line number</li>
<li>-r recursive</li>
<li>-w match whole word</li>
<li>-v invert match</li>
</ul>
</li>
<li><p>regular expression</p>
<ul>
<li>[1-4]   match digits from 1 to 4</li>
<li>[^1-4]  exclude 1 to 4</li>
<li>abc|123 contain abc or 123</li>
</ul>
</li>
<li><p>POSIX:</p>
<ul>
<li>[:alpha:] Any alphabetical character, regardless of case</li>
<li>[:digit:] Any numerical character</li>
<li>[:alnum:] Any alphabetical or numerical character</li>
<li>[:blank:] Space or tab characters</li>
<li>[:xdigit:] Hexadecimal characters; any number or A–F or a–f</li>
<li>[:punct:] Any punctuation symbol</li>
<li>[:print:] Any printable character (not control characters)</li>
<li>[:space:] Any whitespace character</li>
<li>[:graph:] Exclude whitespace characters</li>
<li>[:upper:] Any uppercase letter</li>
<li>[:lower:] Any lowercase letter</li>
<li>[:cntrl:] Control characters</li>
</ul>
</li>
</ul>
<h3 id="skills"><a href="#skills" class="headerlink" title="skills"></a>skills</h3><ul>
<li><p>count the selected lines, we can do as: <code>dmesg |grep -i error |wc -l</code>, or like<br>this <code>dmesg |grep -i error -c</code> </p>
</li>
<li><p>search by match whole word <code>dmesg |grep -w &#39;error&#39;</code></p>
</li>
<li><p><code>grep -rl --include=&quot;*.c&quot; MSG_QUEUE ./</code></p>
</li>
<li><p>select only the lines containing six, seven or eight several times.<br><code>grep -E &quot;(six|seven|eight).*\1&quot; test.txt</code></p>
</li>
<li><p>search contain TAB key, using [CTRL+V][TAB] <code>grep &quot;    504    &quot; test.txt</code></p>
</li>
<li><p><code>grep -r &quot;abc&quot; /root/source</code><br><code>grep -r --include &quot;*.h&quot; &quot;date&quot; path</code><br><code>grep -m 1 &quot;model name&quot; /proc/cpuinfo</code> only display the first match line<br><code>grep -i -E &quot;abc|123&quot;</code> match abc or 123, -i ignore, -E extended regular expression.<br><code>grep -r -l &quot;main&quot; .</code> search all files under each directory, -l files-with-match, -L files-withou-match<br><code>grep -w &quot;linux&quot; *.md</code> match word<br><code>grep -rl --include=*.{h,cpp} &quot;socket&quot; .</code> search socket only with <em>.h </em>.cpp files<br><code>grep --exclude-dir=&quot;_posts&quot; --exclude-dir=&quot;_site&quot;  -r &quot;Dennis&quot; ./</code>  exclude specify directory  </p>
</li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://kukuruku.co/hub/nix/what-is-grep-and-how-do-we-use-it" target="_blank" rel="external">What is grep and how do we use it</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/08/22/grep/" data-id="ciqqpe1qy00arnmpvcjpy8app" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/tools/">tools</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-sed" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/08/22/sed/" class="article-date">
  <time datetime="2014-08-21T16:00:00.000Z" itemprop="datePublished">2014-08-22</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/tools/">tools</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/08/22/sed/">sed</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Basic"><a href="#Basic" class="headerlink" title="Basic"></a>Basic</h3><ul>
<li><p>Syntax</p>
<ul>
<li>-i edit file</li>
<li>-f run script from file, e.g: sed -f script-file test.txt</li>
<li>-n only print the match line</li>
</ul>
</li>
<li><p>command</p>
<ul>
<li>N, add the next line to current buffer for operation</li>
<li>a, append, using for add line</li>
<li>i, insert, using for add line</li>
<li>d, delete, using for delete line</li>
<li>p, print</li>
<li><code>: b t</code>, flow control, “<code>:</code>“ is a label, “<code>b</code>“ means branch and “<code>t</code>“ is test</li>
<li>H,h,G,g,x: put patter space content to storage space</li>
</ul>
</li>
<li><p>regular express</p>
<ul>
<li>^ 表示一行的开头。如：/^#/ 以#开头的匹配。</li>
<li>$ 表示一行的结尾。如：/}$/ 以}结尾的匹配。</li>
<li>\&lt; 表示词首。 如 \&lt;abc 表示以 abc 为首的詞。</li>
<li>> 表示词尾。 如 abc> 表示以 abc 結尾的詞。</li>
<li>. 表示任何单个字符。</li>
<li><ul>
<li>表示某个字符出现了0次或多次。</li>
</ul>
</li>
<li>[ ] 字符集合。 如：[abc]表示匹配a或b或c，还有[a-zA-Z]表示匹配所有的26个字符。如果其中有^表示反，如[^a]表示非a的字符</li>
</ul>
</li>
</ul>
<h3 id="Skills"><a href="#Skills" class="headerlink" title="Skills"></a>Skills</h3><ul>
<li><code>sed [options] &#39;command&#39; file(s)</code>  </li>
<li><code>sed [options] -f scriptfile file(s)</code>  </li>
<li><code>sed -i &#39;/&#39;$prj&#39;/{s/\(.*#.*#\)[0-9]\+/\1&#39;$rev_new&#39;/}&#39; $conf_file</code>, replace revision with new revision</li>
<li><code>sed -n 10,23p filepath</code>, -n print the specific lines  </li>
<li><code>sed &#39;N;s/\n/ /&#39; filepath</code>, join two line into one  </li>
<li><code>echo -e &quot;11\n22\n33\n&quot; | sed -n &#39;/22/{n;p}&#39;</code>, print next line after match  </li>
<li><code>sed &#39;:a;N;s/\n/ /;ba;&#39; file</code>, join all lines (set label <code>a</code>, put the next to<br>operate buffer, substitute <code>\n</code> to space symbol, goto lable <code>a</code>, job continue.</li>
</ul>
<h3 id="sample"><a href="#sample" class="headerlink" title="sample"></a>sample</h3><ul>
<li><ol>
<li><p>delete tags from html, using <code>sed &#39;s/&lt;[^&gt;]*//g&#39; test.html</code></p>
<p><b>This</b> is what <span style="text-decoration: underline;">I</span> meant. Understand?</p>
</li>
</ol>
</li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://coolshell.cn/articles/9104.html" target="_blank" rel="external">sed 简明教程</a></li>
<li><a href="http://www.cnblogs.com/51linux/archive/2011/09/24/2189420.html" target="_blank" rel="external">sed 高级用法</a></li>
<li><a href="http://kodango.com/tag/sed-and-awk/" target="_blank" rel="external">Sed and awk 笔记</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/08/22/sed/" data-id="ciqqpe1r300aunmpvmdj4kdjs" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/tools/">tools</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-awk" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/08/22/awk/" class="article-date">
  <time datetime="2014-08-21T16:00:00.000Z" itemprop="datePublished">2014-08-22</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/tools/">tools</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/08/22/awk/">awk</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Basic"><a href="#Basic" class="headerlink" title="Basic"></a>Basic</h3><ul>
<li>build-in variables<ul>
<li>$0       当前记录（这个变量中存放着整个行的内容）</li>
<li>$1~$n    当前记录的第n个字段，字段间由FS分隔</li>
<li>FS       输入字段分隔符 默认是空格或Tab</li>
<li>NF       当前记录中的字段个数，就是有多少列</li>
<li>NR       已经读出的记录数，就是行号，从1开始，如果有多个文件话，这个值也是不断累加中。</li>
<li>FNR      当前记录数，与NR不同的是，这个值会是各个文件自己的行号</li>
<li>RS       输入的记录分隔符， 默认为换行符</li>
<li>OFS      输出字段分隔符， 默认也是空格</li>
<li>ORS      输出的记录分隔符，默认为换行符</li>
<li>FILENAME 当前输入文件的名字</li>
</ul>
</li>
</ul>
<h3 id="reg"><a href="#reg" class="headerlink" title="reg"></a>reg</h3><ul>
<li>[:alnum:] 字母数字字符 [:alpha:] 字母字符</li>
</ul>
<h3 id="Skills"><a href="#Skills" class="headerlink" title="Skills"></a>Skills</h3><ul>
<li><p><code>awk FS&#39;&#39; &#39;condition1{operator1}condition2{operator2}...&#39; filename</code>  </p>
</li>
<li><p><code>awk &#39;NR==1{print $0}&#39;</code>  </p>
</li>
<li><p><code>arr=($(awk -F&#39;#&#39; &#39;{print $1,$2,$3,$4}&#39; $conf_file))</code>  </p>
</li>
<li><p><code>ps aux | awk &#39;NR==1{print $0}$3&gt;10{print $0}&#39;</code>  </p>
</li>
<li><p><code>awk -F&#39;&lt;|&gt;&#39; &#39;{if(NF&gt;3){print $2 &quot;:&quot; $3}}&#39; /tmp/test.xml</code> parse xml file  </p>
</li>
<li><p><code>awk -F&#39;=&#39; &#39;/HWADDR/{print $2}&#39; /etc/sysconfig/network-scripts/ifcfg-eth0</code></p>
</li>
<li><p><code>ip -o link show eth0 |awk &#39;{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,&quot;\\1&quot;, 1)); }&#39;</code></p>
</li>
<li><p><code>awk &#39;END{print $0}&#39; /root/test.log</code> print the last line</p>
</li>
<li><p><code>lvdisplay |awk &#39;/LV Name/{n=$3} /Block device/{d=$3; sub(&quot;.*:&quot;,&quot;dm-&quot;,d); print d,n;}&#39;</code><br> print the mapping relationship of dm-*</p>
</li>
<li><p>statistics</p>
<p>count the total size of all c files <code>ls -l src/*.c |awk &#39;{sum+=$5} END {print sum}&#39;</code> </p>
</li>
<li><p>BEGIN, END</p>
</li>
</ul>
<p>the origin content:</p>
<pre><code>$ cat score.txt
Marry   2143 78 84 77
Jack    2321 66 78 45
Tom     2122 48 77 71
Mike    2537 87 97 95
Bob     2415 40 57 62
</code></pre><p>the awk script:</p>
<pre><code>$ cat cal.awk
#!/bin/awk -f
#运行前
BEGIN {
    math = 0
    english = 0
    computer = 0

    printf &quot;NAME    NO.   MATH  ENGLISH  COMPUTER   TOTAL\n&quot;
    printf &quot;---------------------------------------------\n&quot;
}
#运行中
{
    math+=$3
    english+=$4
    computer+=$5
    printf &quot;%-6s %-6s %4d %8d %8d %8d\n&quot;, $1, $2, $3,$4,$5, $3+$4+$5
}
#运行后
END {
    printf &quot;---------------------------------------------\n&quot;
    printf &quot;  TOTAL:%10d %8d %8d \n&quot;, math, english, computer
    printf &quot;AVERAGE:%10.2f %8.2f %8.2f\n&quot;, math/NR, english/NR, computer/NR
}
</code></pre><p>execute the script:</p>
<pre><code>$ awk -f cal.awk score.txt
NAME    NO.   MATH  ENGLISH  COMPUTER   TOTAL
---------------------------------------------
Marry  2143     78       84       77      239
Jack   2321     66       78       45      189
Tom    2122     48       77       71      196
Mike   2537     87       97       95      279
Bob    2415     40       57       62      159
---------------------------------------------
  TOTAL:       319      393      350
AVERAGE:     63.80    78.60    70.00
</code></pre><ul>
<li>ls -l |awk ‘$6 == “Dec”‘</li>
<li><code>netstat -apn |grep 3260 |awk &#39;{if($2&gt;0||$3&gt;0){print $0}}&#39;</code> print lines if Recv-Q<br>or Send-Q large than 0</li>
<li><code>cat /tmp/.nic |awk &#39;{print $1,$2}&#39;|awk &#39;{aa[$1]=aa[$1]&quot;,&quot;$2;asorti(aa,tA);}END{for(i in tA)print aa[tA[i]]}&#39;|sed &#39;s/^,//&#39;</code></li>
<li><code>echo -e &quot;12345\na25\nt123&quot; | awk &#39;/a25/{print a;}{a=$0}&#39;</code> print the previous line of match line</li>
</ul>
<h3 id="For-more"><a href="#For-more" class="headerlink" title="For more"></a>For more</h3><ul>
<li><a href="http://www.gnu.org/software/gawk/manual/gawk.html#Built_002din-Variables" target="_blank" rel="external">内建变量</a></li>
<li><a href="http://www.gnu.org/software/gawk/manual/gawk.html#Statements" target="_blank" rel="external">流控方面</a></li>
<li><a href="http://www.gnu.org/software/gawk/manual/gawk.html#Built_002din" target="_blank" rel="external">内建函数</a></li>
<li><a href="http://www.gnu.org/software/gawk/manual/gawk.html#Regexp" target="_blank" rel="external">正则表达式</a></li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://coolshell.cn/articles/9070.html" target="_blank" rel="external">awk 简明教程</a></li>
<li><a href="http://www.cnblogs.com/chengmo/archive/2010/10/09/1846696.html" target="_blank" rel="external">数组排序多种实现方法</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/08/22/awk/" data-id="ciqqpe1qv00aonmpvgqdkrp4c" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/tools/">tools</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-optimal-file-system-with-tune2fs" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2014/08/09/optimal-file-system-with-tune2fs/" class="article-date">
  <time datetime="2014-08-08T16:00:00.000Z" itemprop="datePublished">2014-08-09</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/storage/">storage</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2014/08/09/optimal-file-system-with-tune2fs/">optimal file system with tune2fs</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="view-filesystem-information"><a href="#view-filesystem-information" class="headerlink" title="view filesystem information"></a>view filesystem information</h3><pre><code>dennis@dennis:~$ sudo su
[sudo] password for dennis: 
root@dennis:/home/dennis# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000ee377

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *     1026048     1230847      102400    7  HPFS/NTFS/exFAT
/dev/sda2         1230848   210741247   104755200    7  HPFS/NTFS/exFAT
/dev/sda3       210741248   860366847   324812800    7  HPFS/NTFS/exFAT
/dev/sda4       860368894  1953523711   546577409    5  Extended
Partition 4 does not start on physical sector boundary.
/dev/sda5       860368896  1937033215   538332160   83  Linux
/dev/sda6      1937035264  1953523711     8244224   82  Linux swap / Solaris
root@dennis:/home/dennis# tune2fs -l /dev/sda1
tune2fs 1.42 (29-Nov-2011)
tune2fs: Bad magic number in super-block while trying to open /dev/sda1
Couldn&apos;t find valid filesystem superblock.
root@dennis:/home/dennis# tune2fs -l /dev/sda6
tune2fs 1.42 (29-Nov-2011)
tune2fs: Bad magic number in super-block while trying to open /dev/sda6
Couldn&apos;t find valid filesystem superblock.
root@dennis:/home/dennis# tune2fs -l /dev/sda5
tune2fs 1.42 (29-Nov-2011)
Filesystem volume name:   &lt;none&gt;
Last mounted on:          /
Filesystem UUID:          cab5dcf8-904f-4f53-a2f8-25276e38f84d
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              33652736
Block count:              134583040
Reserved block count:     6729152
Free blocks:              112706967
Free inodes:              33202652
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      991
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Thu Mar 27 19:19:17 2014
Last mount time:          Sat Aug  9 13:51:31 2014
Last write time:          Wed Apr  9 11:19:12 2014
Mount count:              94
Maximum mount count:      -1
Last checked:             Thu Mar 27 19:19:17 2014
Check interval:           0 (&lt;none&gt;)
Lifetime writes:          174 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
First orphan inode:       18089038
Default directory hash:   half_md4
Directory Hash Seed:      d4c17cf0-bb57-4423-81ab-a8fc3df1bc13
Journal backup:           inode blocks
</code></pre><h3 id="Terminology"><a href="#Terminology" class="headerlink" title="Terminology"></a>Terminology</h3><p>The block size is the unit of work for the file system. Every read and write is<br>done in full multiples of the block size. The block size is also the smallest<br>size on disk a file can have.</p>
<h3 id="Optimal"><a href="#Optimal" class="headerlink" title="Optimal"></a>Optimal</h3><p>1.Inode block</p>
<p>2.Reserved block</p>
<pre><code>Mkfs.ext3 –b 4096 - i 8192 –m 2 /dev/sda5
</code></pre><p>3.tune2fs</p>
<pre><code>dennis@dennis:~$ tune2fs
tune2fs 1.42 (29-Nov-2011)
Usage: tune2fs [-c max_mounts_count] [-e errors_behavior] [-g group]
    [-i interval[d|m|w]] [-j] [-J journal_options] [-l]
    [-m reserved_blocks_percent] [-o [^]mount_options[,...]] [-p mmp_update_interval]
    [-r reserved_blocks_count] [-u user] [-C mount_count] [-L volume_label]
    [-M last_mounted_dir] [-O [^]feature[,...]]
    [-E extended-option[,...]] [-T last_check_time] [-U UUID]
    [ -I new_inode_size ] device
</code></pre><p>use <code>tune2fs -l /dev/sda5</code> to view filesystem information</p>
<p>use <code>tune2fs -c -1 /dev/sda5</code> to avoid selfcheck</p>
<p>use <code>tune2fs -c -1 -i 0 /dev/sda5</code> to set the interval time</p>
<p>use <code>tune2fs -m 3 /dev/sda5</code> to set the reserved_blocks_percent</p>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://linux.chinaitlab.com/administer/824245.html" target="_blank" rel="external">优化linux文件系统 提高读写速度</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2014/08/09/optimal-file-system-with-tune2fs/" data-id="ciqqpe1qs00alnmpv57vq2stx" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/filesystem/">filesystem</a></li></ul>

    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    <a class="extend prev" rel="prev" href="/page/5/">&laquo; __('prev')</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/4/">4</a><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/page/7/">7</a><a class="page-number" href="/page/8/">8</a><span class="space">&hellip;</span><a class="page-number" href="/page/18/">18</a><a class="extend next" rel="next" href="/page/7/">__('next') &raquo;</a>
  </nav>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Catégories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/blog/">blog</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/english/">english</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/kernel/">kernel</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/language/">language</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/math/">math</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/network/">network</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/others/">others</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/person/">person</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/program/">program</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/source/">source</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/storage/">storage</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/tools/">tools</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/windows/">windows</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Mot-clés</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/FAQ/">FAQ</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/IRC/">IRC</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Translation/">Translation</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/">android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/api/">api</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/assembly/">assembly</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/awk/">awk</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/batch/">batch</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/blog/">blog</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/book/">book</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/crash/">crash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/debug/">debug</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dot/">dot</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/driver/">driver</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/emacs/">emacs</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/exploit/">exploit</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/file-system/">file system</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/filesystem/">filesystem</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/flowchart/">flowchart</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gcc/">gcc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/google/">google</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/graphviz/">graphviz</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hosts/">hosts</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/iscsi/">iscsi</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javascript/">javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/job/">job</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/json/">json</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kernel/">kernel</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/lisp/">lisp</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/lua/">lua</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/makefile/">makefile</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/malloc/">malloc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/math/">math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/maxima/">maxima</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memory/">memory</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memory-overflow/">memory overflow</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mtrace/">mtrace</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netdisk/">netdisk</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/network/">network</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/others/">others</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pandoc/">pandoc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/performance/">performance</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/person/">person</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rsync/">rsync</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sed/">sed</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shell/">shell</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/skype/">skype</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sms/">sms</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/source/">source</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ssh/">ssh</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/stack/">stack</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/storage/">storage</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/study/">study</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/svn/">svn</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sync/">sync</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/time/">time</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tools/">tools</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/valgrind/">valgrind</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vi/">vi</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/virtual/">virtual</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wget/">wget</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows/">windows</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wireshark/">wireshark</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/write/">write</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xml/">xml</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Nuage de mot-clés</h3>
    <div class="widget tagcloud">
      <a href="/tags/FAQ/" style="font-size: 10px;">FAQ</a> <a href="/tags/IRC/" style="font-size: 10px;">IRC</a> <a href="/tags/Translation/" style="font-size: 13px;">Translation</a> <a href="/tags/android/" style="font-size: 10px;">android</a> <a href="/tags/api/" style="font-size: 10px;">api</a> <a href="/tags/assembly/" style="font-size: 10px;">assembly</a> <a href="/tags/awk/" style="font-size: 11px;">awk</a> <a href="/tags/batch/" style="font-size: 14px;">batch</a> <a href="/tags/blog/" style="font-size: 10px;">blog</a> <a href="/tags/book/" style="font-size: 10px;">book</a> <a href="/tags/c/" style="font-size: 16px;">c</a> <a href="/tags/c/" style="font-size: 19px;">c++</a> <a href="/tags/cache/" style="font-size: 10px;">cache</a> <a href="/tags/crash/" style="font-size: 10px;">crash</a> <a href="/tags/database/" style="font-size: 17px;">database</a> <a href="/tags/debug/" style="font-size: 12px;">debug</a> <a href="/tags/dot/" style="font-size: 10px;">dot</a> <a href="/tags/driver/" style="font-size: 10px;">driver</a> <a href="/tags/emacs/" style="font-size: 11px;">emacs</a> <a href="/tags/exploit/" style="font-size: 10px;">exploit</a> <a href="/tags/file-system/" style="font-size: 10px;">file system</a> <a href="/tags/filesystem/" style="font-size: 12px;">filesystem</a> <a href="/tags/flowchart/" style="font-size: 10px;">flowchart</a> <a href="/tags/gcc/" style="font-size: 10px;">gcc</a> <a href="/tags/git/" style="font-size: 12px;">git</a> <a href="/tags/google/" style="font-size: 11px;">google</a> <a href="/tags/graphviz/" style="font-size: 11px;">graphviz</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/hosts/" style="font-size: 10px;">hosts</a> <a href="/tags/iscsi/" style="font-size: 14px;">iscsi</a> <a href="/tags/java/" style="font-size: 10px;">java</a> <a href="/tags/javascript/" style="font-size: 10px;">javascript</a> <a href="/tags/job/" style="font-size: 10px;">job</a> <a href="/tags/json/" style="font-size: 10px;">json</a> <a href="/tags/kernel/" style="font-size: 14px;">kernel</a> <a href="/tags/linux/" style="font-size: 14px;">linux</a> <a href="/tags/lisp/" style="font-size: 10px;">lisp</a> <a href="/tags/lua/" style="font-size: 10px;">lua</a> <a href="/tags/makefile/" style="font-size: 10px;">makefile</a> <a href="/tags/malloc/" style="font-size: 10px;">malloc</a> <a href="/tags/math/" style="font-size: 11px;">math</a> <a href="/tags/maxima/" style="font-size: 10px;">maxima</a> <a href="/tags/memory/" style="font-size: 11px;">memory</a> <a href="/tags/memory-overflow/" style="font-size: 10px;">memory overflow</a> <a href="/tags/mtrace/" style="font-size: 10px;">mtrace</a> <a href="/tags/netdisk/" style="font-size: 10px;">netdisk</a> <a href="/tags/network/" style="font-size: 20px;">network</a> <a href="/tags/others/" style="font-size: 18px;">others</a> <a href="/tags/pandoc/" style="font-size: 10px;">pandoc</a> <a href="/tags/performance/" style="font-size: 16px;">performance</a> <a href="/tags/person/" style="font-size: 11px;">person</a> <a href="/tags/protobuf/" style="font-size: 11px;">protobuf</a> <a href="/tags/python/" style="font-size: 10px;">python</a> <a href="/tags/rsync/" style="font-size: 10px;">rsync</a> <a href="/tags/sed/" style="font-size: 11px;">sed</a> <a href="/tags/shell/" style="font-size: 15px;">shell</a> <a href="/tags/skype/" style="font-size: 11px;">skype</a> <a href="/tags/sms/" style="font-size: 10px;">sms</a> <a href="/tags/source/" style="font-size: 11px;">source</a> <a href="/tags/ssh/" style="font-size: 10px;">ssh</a> <a href="/tags/stack/" style="font-size: 10px;">stack</a> <a href="/tags/storage/" style="font-size: 15px;">storage</a> <a href="/tags/study/" style="font-size: 10px;">study</a> <a href="/tags/svn/" style="font-size: 11px;">svn</a> <a href="/tags/sync/" style="font-size: 10px;">sync</a> <a href="/tags/test/" style="font-size: 11px;">test</a> <a href="/tags/time/" style="font-size: 10px;">time</a> <a href="/tags/tools/" style="font-size: 16px;">tools</a> <a href="/tags/valgrind/" style="font-size: 10px;">valgrind</a> <a href="/tags/vi/" style="font-size: 10px;">vi</a> <a href="/tags/vim/" style="font-size: 14px;">vim</a> <a href="/tags/virtual/" style="font-size: 11px;">virtual</a> <a href="/tags/wget/" style="font-size: 10px;">wget</a> <a href="/tags/windows/" style="font-size: 11px;">windows</a> <a href="/tags/wireshark/" style="font-size: 10px;">wireshark</a> <a href="/tags/write/" style="font-size: 13px;">write</a> <a href="/tags/xml/" style="font-size: 10px;">xml</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">July 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">April 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">March 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/02/">February 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">October 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">September 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">August 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/07/">July 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">June 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/03/">March 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/02/">February 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/01/">January 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/12/">December 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/11/">November 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/09/">September 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/08/">August 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/07/">July 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/06/">June 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/05/">May 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/03/">March 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/11/">November 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/10/">October 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/09/">September 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/08/">August 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/07/">July 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/06/">June 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/05/">May 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/04/">April 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/03/">March 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/02/">February 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/12/">December 2012</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/09/">September 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Articles récents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/07/17/how-to-implement-malloc/">如何实现一个malloc</a>
          </li>
        
          <li>
            <a href="/2016/07/17/study-grep-more/">grep工作原理</a>
          </li>
        
          <li>
            <a href="/2016/07/17/2016-04-13-malloc/">malloc</a>
          </li>
        
          <li>
            <a href="/2016/04/27/include-what-you-use/">使用IWYU整理头文件引用</a>
          </li>
        
          <li>
            <a href="/2016/04/24/understand-gcc-assembly-output/">understand gcc assembly output</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 Matrix207<br>
      Propulsé by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>